package com.hkfg.controller;

import com.hkfg.domain.User;
import com.hkfg.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller   // bean
@ResponseBody
@CrossOrigin
//@RestController   // 相当于上面两个
//@RequestMapping("/homepage")  // 请求路径前缀
public class HomepageController {

    @Autowired
    private UserServiceImpl userService;

    /**
     * 发送欢迎语
     * @param id
     * @return
     */
    @RequestMapping(value = "/welcome", method = RequestMethod.GET)
    public String sendWel(@RequestParam("token") String id){
        User user = new User();
        user = userService.getUserById(Integer.parseInt(id));
        return user.getDescription();
    }

    /**
     * 修改欢迎语
     * @param id
     * @param description
     * @return
     */
    @RequestMapping(value = "/modifywelcome", method = RequestMethod.GET)
    public int sendWel(@RequestParam("token") String id, String description){
        System.out.println(description);
        return userService.modifyWelcome(Integer.parseInt(id), description);
    }


}
